package com.ruyuan.event.streaming.schema;
import com.ruyuan.event.streaming.pojo.EventServerLog;
import org.apache.flink.api.common.serialization.DeserializationSchema;
import org.apache.flink.api.common.serialization.SerializationSchema;
import org.apache.flink.api.common.typeinfo.TypeHint;
import org.apache.flink.api.common.typeinfo.TypeInformation;
import java.io.IOException;

/**
 * 自定义序列化
 * */
public class EventServerLogSchema implements DeserializationSchema<EventServerLog>, SerializationSchema<EventServerLog> {

    /**
     * 反序列化的方法
     * */
    @Override
    public EventServerLog deserialize(byte[] message) throws IOException {
        //返回对象
        return EventServerLog.parseFrom(message);
    }

    //是否是流的结尾
    @Override
    public boolean isEndOfStream(EventServerLog nextElement) {
        return false;
    }

    //序列化的方法
    @Override
    public byte[] serialize(EventServerLog eventServerLog) {
        return eventServerLog.toByteArray();
    }
    //指定反序列化以后对象的类型
    @Override
    public TypeInformation<EventServerLog> getProducedType() {
        return TypeInformation.of(new TypeHint<EventServerLog>() {});
    }
}
